package cn.mumzone.pos.ui.adapter;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.widget.TextView;

import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.StringUtils;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.BillConsumeDetailsEntity;
import cn.mumzone.pos.ui.widgets.util.StringSpanUtils;

/**
 * Created By Dlx
 * on 2019/6/29
 */
public class ADA_BillServiceDetail extends CommonAdapter<BillConsumeDetailsEntity.ListBean> {
    private Context mContext;

    public ADA_BillServiceDetail(Context context) {
        super(context);
        mContext = context;
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.item_bill_detail_service;
    }

    @Override
    protected void convert(ViewHolder holder, BillConsumeDetailsEntity.ListBean entity, int position) {
        bindServiceData(holder, entity, position);
    }


    private SpannableStringBuilder getDeleteLineText(String str) {
        return StringSpanUtils.init().addForegroundColorHighLight(mContext.getResources().getColor(R.color.order_status_close), "￥" + str)
                .setDeleteLineWithKeyAndPosition("￥" + str, 0)
                .build();
    }

    private void bindServiceData(ViewHolder holder, BillConsumeDetailsEntity.ListBean entity, int position) {
        holder.setText(R.id.service_name_tv, entity.getServiceName());
        holder.setText(R.id.service_technician_name_tv, "服务技师：" + entity.getTechnicianName());

        holder.setSpanText(R.id.service_price_tv, entity.getPrice().equals(entity.getMemberPrice()) ? new SpannableStringBuilder() :
                StringUtils.isEmpty(entity.getMemberPrice()) ? new SpannableStringBuilder() : getDeleteLineText(entity.getPrice()));

        holder.setText(R.id.service_real_price_tv, "￥" + ((StringUtils.isEmpty(entity.getMemberPrice()) || "0".equals(entity.getMemberPrice())) ? entity.getPrice() : entity.getMemberPrice()));
    }

    private SpannableStringBuilder addServiceItemLabel(BillConsumeDetailsEntity.ListBean entity, TextView textView) {
        StringSpanUtils utils = StringSpanUtils.init().addStr(entity.getServiceName());
        if (!entity.getPrice().equals(entity.getRealPay())) {
            utils.addRoundRectLabelWithRadius("议价", textView,
                    mContext.getResources().getColor(R.color.white_color),
                    mContext.getResources().getColor(R.color.order_status_service),
                    1, 1, 1, 0, true);
        }
        return utils.build();
    }

}
